package com.liu.manager.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.liu.manager.bean.ResponseResult;
import com.liu.manager.entity.RolerAndPermission;
import com.liu.manager.entity.Syspermission;
import com.liu.manager.service.RolerAndPermissionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/rolerandpermi")
public class RolerAndPermiController {

    @Resource
    RolerAndPermissionService rolerAndPermissionService;

    @PostMapping(value = "/addRolerAndPermission",produces = {"application/json;charset=utf-8"})
    public String addRoler(@RequestBody RolerAndPermission rolerAndPermission){
        ResponseResult responseResult = rolerAndPermissionService.insertRolerAndPermission(rolerAndPermission);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @PostMapping(value = "/removeRolerAndPermission",produces = {"application/json;charset=utf-8"})
    public String removeRolerAndPermission(long id){
        ResponseResult responseResult = rolerAndPermissionService.deleteRolerAndPermission(id);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @GetMapping(value = "/findByRolerId",produces = {"application/json;charset=utf-8"})
    public String findByRolerId(long rolerId){
        ResponseResult responseResult = rolerAndPermissionService.findByRolerId(rolerId);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }

    @GetMapping(value = "/findByPermissionId",produces = {"application/json;charset=utf-8"})
    public String findByPermissionId(long pid){
        ResponseResult responseResult = rolerAndPermissionService.findByPermissionId(pid);
        return JSON.toJSONString(responseResult, JSONWriter.Feature.FieldBased,JSONWriter.Feature.WriteNulls);
    }
}
